#!/bin/bash
echo "📋 mingw64 目录详细差异分析"
echo "=========================================="

PATH1="/c/msys64/mingw64"
PATH2="/d/mingw64"

analyze_differences() {
    echo "🔧 分析关键工具差异..."
    
    # 关键开发工具对比
    key_tools=("gcc.exe" "g++.exe" "gdb.exe" "make.exe" "windres.exe" "ar.exe")
    
    echo "关键开发工具对比:"
    for tool in "${key_tools[@]}"; do
        tool1="$PATH1/bin/$tool"
        tool2="$PATH2/bin/$tool"
        
        if [ -f "$tool1" ] && [ -f "$tool2" ]; then
            size1=$(stat -c%s "$tool1" 2>/dev/null || stat -f%z "$tool1" 2>/dev/null)
            size2=$(stat -c%s "$tool2" 2>/dev/null || stat -f%z "$tool2" 2>/dev/null)
            echo "  $tool: $(numfmt --to=iec $size1) vs $(numfmt --to=iec $size2)"
        elif [ -f "$tool1" ]; then
            echo "  $tool: ✅ 只在路径1存在"
        elif [ -f "$tool2" ]; then
            echo "  $tool: ✅ 只在路径2存在"
        else
            echo "  $tool: ❌ 都不存在"
        fi
    done
    
    echo ""
    echo "📁 目录结构差异:"
    
    # 比较目录结构
    echo "路径1独有的目录:"
    (cd "$PATH1" && find . -type d -maxdepth 1 2>/dev/null | sort) > dirs1.txt
    (cd "$PATH2" && find . -type d -maxdepth 1 2>/dev/null | sort) > dirs2.txt
    comm -23 dirs1.txt dirs2.txt | sed 's/^/  /'
    
    echo ""
    echo "路径2独有的目录:"
    comm -13 dirs1.txt dirs2.txt | sed 's/^/  /'
    
    rm -f dirs1.txt dirs2.txt
}

check_versions() {
    echo ""
    echo "🔄 版本信息对比:"
    
    # GCC版本
    if [ -f "$PATH1/bin/gcc.exe" ]; then
        echo "路径1 GCC: $("$PATH1/bin/gcc.exe" --version | head -1)"
    fi
    if [ -f "$PATH2/bin/gcc.exe" ]; then
        echo "路径2 GCC: $("$PATH2/bin/gcc.exe" --version | head -1)"
    fi
    
    # 目标平台
    if [ -f "$PATH1/bin/gcc.exe" ]; then
        echo "路径1 目标: $("$PATH1/bin/gcc.exe" -dumpmachine)"
    fi
    if [ -f "$PATH2/bin/gcc.exe" ]; then
        echo "路径2 目标: $("$PATH2/bin/gcc.exe" -dumpmachine)"
    fi
}

# 执行分析
analyze_differences
check_versions

echo ""
echo "💡 分析总结:"
echo "- /c/msys64/mingw64: MSYS2环境中的mingw64工具链"
echo "- /d/mingw64: 可能是独立安装的MinGW-w64"
echo "- 两者可能有版本、配置或完整性的差异"
